<?php

namespace Home\Model;
use Think\Model;

/**
 * 收藏模型
 */
class CollectModel extends Model
{
	/**
	 * 收藏列表
	 * @param  [int] $uid      [收藏人id]
	 * @param  int $c_uid      [被收藏人id]
	 * @param  int $teaching   [教or学]
	 * @return [array]         [数据列表]
	 * @author qlj
	 */
	public function collectList($uid,$c_uid='',$teaching=''){
		if (!empty($uid)) {
			$where['c.uid'] = $uid;
		}
		if (!empty($c_uid)) {
			$where['c.c_uid'] = $c_uid;
		}
		if (!empty($teaching)) {
			$where['c.teaching'] = $teaching;
			if ($teaching == 2) {
				$where['u.end_teach'] = 0;
			} elseif ($teaching == 1) {
				$where['u.end_study'] = 0;
			}
		}
		$where['c.status'] = 1;
		return $this -> alias('c') -> field('c.id,c.c_uid,u.nickname,u.logo,u.sex,u.age,u.area_id,u.students') -> join('tutor_user_member as u on c.c_uid=u.id') -> where($where) -> select();
	}
}